#include "Computer.h"
#include <string.h>
#include <iostream>

using std::cout;
using std::endl;


/**
 * 构造方法
 * @param price
 * @param brand
 * @return
 */
Computer::Computer(double price, const char *brand)
        : _price(price), _brand(new char[strlen(brand) + 1]()) {
    strcpy(_brand, brand);
    cout << "Constructor" << endl;
}

/**
 * @brief 析构函数
 */
Computer::~Computer() {
    if(_brand){
        delete[] _brand;
        _brand = nullptr;
    }
}

/**
 * @brief 打印单例的内容
 */
string Computer::toString() const {
    return "(" + std::to_string(this->_price)
           + "," + this->_brand
           + ")";
}

Computer::Computer(const Computer &rhs)
        : _price(rhs._price), _brand(new char[strlen(rhs._brand) + 1]()) {
    strcpy(_brand, rhs._brand);
}

Computer &Computer::operator=(const Computer &rhs) {
    if(&rhs != this){
        _price = rhs._price;

        delete[] _brand;
        _brand = new char[strlen(rhs._brand) + 1]();
        strcpy(_brand, rhs._brand);

    }
    return *this;
}